<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>评价</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="/node_modules/LobsterUIFrame/weui/css/weui.css" />
    <link rel="stylesheet" href="/node_modules/LobsterUIFrame/weui/css/weuix.css" />
    <script src="/node_modules/LobsterUIFrame/weui/js/zepto.min.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/zepto.weui.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/swipe.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/macy.js"></script>
    <script src="/node_modules/LobsterUIFrame/weui/js/php.js"></script>
    <script src="/lobstersdk/lobster.js"></script>
    <script src="/jslib/template-web.js"></script>
    <style>

    </style>
</head>

<body ontouchstart>

    <div class="weui-loadmore" id="more">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">正在加载</span>
    </div>
</body>

</html>

<script type="text/template" id="evaluatelisttemp">
    {{each list item}}
     <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
        <div class="weui-media-box__hd">
            <img class="weui-media-box__thumb" src="{{item.UserImg}}" alt="">
        </div>
        <div class="weui-media-box__bd">
            <h4 class="weui-media-box__title">{{item.UserName}}</h4>
            <p class="weui-media-box__desc">{{(item.EvaluateTime||"").substring(0,19)}} {{item.SpecName}}</p>
            <div id="ss" class="f-green"> {{item.Startxt}}</div>
            <div class="weui-media-box__desc">{{item.Cont}}</div>
        </div>
    </a>
    {{/each}}
</script>
<script>

    lobsterh5.main({
        data: {
            evaluatelist: [],
            page: 1,
            limit: 10,
            hasmore:true,
            GoodsId: 0,
        },
        //初始化页面
        pageload: function () {
            var self = this;
            self.data.GoodsId = lobsterh5.GetUrlParam("goodsId");
            self.getevaluatelist();
            self.initevent();
        },
        //初始化事件
        initevent: function () {
            var self = this;
            $(window).scroll(
                self.debounce(
                    function () {
                        let pageHeight = Math.max(document.body.scrollHeight, document.body.offsetHeight);
                        let viewportHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0;
                        let scrollHeight = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
                        if (pageHeight - viewportHeight - scrollHeight < 50) {
                            self.getevaluatelist();
                        }
                    }), 1000);
        }, 
        debounce: function (fn, interval) {
            let timer = null; // 定时器
            return function () {
                // 清除上一次的定时器
                clearTimeout(timer);
                // 拿到当前的函数作用域
                let _this = this;
                // 拿到当前函数的参数数组
                let args = Array.prototype.slice.call(arguments, 0);
                // 开启倒计时定时器
                timer = setTimeout(function () {
                    // 通过apply传递当前函数this，以及参数
                    fn.apply(_this, args);
                    // 默认300ms执行
                }, interval || 300)
            }
        },
        getevaluatelist: function () {
            var self = this;
            if (!self.data.hasmore) return;
            $("#more").show();
            lobsterh5.GET("/lowcode/APP20200616102057595/shop/?fun=mall.getevaluatelist&workid=" + lobsterh5.GetWorkId(), {
                page: self.data.page, limit: self.data.limit,
                goodsId: self.data.GoodsId
            }).then(res => {
                self.data.evaluatelist = res.data;
                self.data.evaluatelist.forEach(a => {
                    a.Startxt = '★★★★★☆☆☆☆☆'.substring(5 - a.Star, 10 - a.Star);
                })
                var html = template("evaluatelisttemp", { list: self.data.evaluatelist });
                $("#more").before(html);
                if (res.data.length < self.data.limit) {
                    self.data.hasmore = false;
                    $("#more").text("没有更多了");
                } else {
                    $("#more").hide();
                    self.data.page++;
                }
            }).catch(res => {
                $.toast(res.msg, 'forbidden');

            })
        },
    })
</script>